package com.parkingspace.controller;


import com.parkingspace.entity.User;
import com.parkingspace.service.IUserService;
import com.parkingspace.util.Constants;
import com.parkingspace.util.ResultVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author Gapper
 * @since 2021-05-24
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private IUserService iUserService;

    @GetMapping("/findUserByUid/{uid}")
    public ResultVO findUserByUid(@PathVariable("uid") Long uid){
            Map<String,Object> map = iUserService.findUserByUid(uid);
            return new ResultVO(Constants.OPER_SUCCESS,"",map);
    }

    @PutMapping("/updateUser/{uid}")
    public ResultVO updateUser (@PathVariable("uid") Long uid, User user) {
        try {
            Boolean aBoolean = iUserService.updateUser(uid, user);
            return new ResultVO(Constants.OPER_SUCCESS,"请求成功!",aBoolean);
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultVO(Constants.OPER_FAILURE,e.getMessage(),"请求失败!");
        }
    }

}

